/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.pay.component;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import com.qihoo.gamecenter.sdk.common.h.g;
import com.qihoo.gamecenter.sdk.common.i.i;
import com.qihoo.gamecenter.sdk.common.i.s;
import com.qihoo.gamecenter.sdk.pay.j.u;
import com.qihoo.gamecenter.sdk.pay.res.b;
import org.json.JSONObject;

public class PayCServiceIndicator extends APayWidget {
    private TextView c;
    private View d;
    private u e;

    public PayCServiceIndicator(Context paramContext) {
        super(paramContext);
        setGravity(16);
        this.b.a(this, new ColorDrawable(0), new ColorDrawable(2146496752), new ColorDrawable(0));
        int i = s.b(paramContext, 2.0F);
        setPadding(i * 3 / 2, i, i * 3 / 2, i * 3 / 2);
        b();
    }

    private void b() {
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(s.b(getContext(), 20.0F), s.b(
                getContext(), 15.0F));
        localLayoutParams.bottomMargin = s.b(getContext(), 6.0F);
        this.c = new TextView(getContext());
        this.c.setLayoutParams(localLayoutParams);
        this.c.setPadding(0, 0, 0, 2);
        this.c.setTextColor(-1);
        this.c.setGravity(17);
        this.c.setVisibility(8);
        this.c.setTextSize(1, s.a(getContext(), 10.0F));
        this.b.a(this.c, 1073741879);
        addView(this.c);
        localLayoutParams = new RelativeLayout.LayoutParams(s.b(getContext(), 21.0F), s.b(getContext(), 21.0F));
        localLayoutParams.topMargin = s.b(getContext(), 1.0F);
        this.d = new View(getContext());
        this.d.setLayoutParams(localLayoutParams);
        this.b.a(this.d, 1073741880);
        addView(this.d);
    }

    public boolean a() {
        return ((this.c != null) && (this.c.getVisibility() == 0));
    }

    private void a(boolean paramBoolean) {
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(s.b(getContext(), 21.0F), s.b(
                getContext(), 21.0F));
        localLayoutParams.topMargin = s.b(getContext(), 1.0F);
        localLayoutParams.leftMargin = ((paramBoolean) ? s.b(getContext(), 16.0F) : 0);
        updateViewLayout(this.d, localLayoutParams);
    }

    private void b(int paramInt) {
        if (this.c == null)
            return;
        AnimationSet localAnimationSet;
        if (paramInt <= 0) {
            if (this.c.getVisibility() == 0) {
                localAnimationSet = new AnimationSet(true);
                localAnimationSet.addAnimation(new AlphaAnimation(1.0F, 0.0F));
                localAnimationSet.setDuration(250L);
                this.c.startAnimation(localAnimationSet);
                this.c.setVisibility(8);
            }
            a(false);
        }
        else {
            if (this.c.getVisibility() != 0) {
                localAnimationSet = new AnimationSet(true);
                localAnimationSet.addAnimation(new AlphaAnimation(0.5F, 1.0F));
                localAnimationSet.addAnimation(new ScaleAnimation(0.1F, 1.0F, 0.1F, 1.0F, 1, 1.0F, 1, 1.0F));
                localAnimationSet.setDuration(250L);
                this.c.setVisibility(0);
                this.c.startAnimation(localAnimationSet);
            }
            if (paramInt >= 100)
                this.c.setText("99+");
            else
                this.c.setText(String.valueOf(paramInt));
            a(true);
        }
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.e == null)
            return;
        this.e.cancel(true);
        this.e = null;
    }

    public void a(Activity paramActivity, Intent paramIntent) {
        if (this.e != null)
            this.e.cancel(true);
        this.e = new u(paramActivity, paramIntent);
        this.e.a(new g() {
            public void a(String paramString, Context paramContext) {
                JSONObject localJSONObject = i.a(paramString);
                if (localJSONObject == null)
                    return;
                int i = localJSONObject.optInt("error_code", -1);
                if (i != 0)
                    return;
                localJSONObject = localJSONObject.optJSONObject("content");
                if (localJSONObject == null)
                    return;
                PayCServiceIndicator.a(PayCServiceIndicator.this, localJSONObject.optInt("reply_num"));
            }
        }, new String[0]);
    }
}